package com.chunhe.sojourn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chunhe.sojourn.app.dao.LinkUrlDao;
import com.chunhe.sojourn.app.domain.LinkUrl;
import com.chunhe.sojourn.app.service.LinkUrlService;
import com.chunhe.sojourn.common.domain.QueryRequest;
import com.chunhe.sojourn.common.utils.SortUtil;
import org.springframework.stereotype.Service;

@Service
public class LinkUrlServiceImpl extends ServiceImpl<LinkUrlDao, LinkUrl> implements LinkUrlService {
    @Override
    public IPage<LinkUrl> getPage(QueryRequest request, LinkUrl linkUrl) {
        Page<LinkUrl> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        LambdaQueryWrapper<LinkUrl> lambdaQueryWrapper = new LambdaQueryWrapper<LinkUrl>()
                .eq(LinkUrl::getChannelCode, linkUrl.getChannelCode())
                .orderByDesc(LinkUrl::getSort).orderByAsc(LinkUrl::getId);
        return this.page(page, lambdaQueryWrapper);

    }
}
